<template>
  <div>	 
  	<header class="classification_t header_fixed" id="title">
      <div class="classification_t_l" @click="goPrev">
        <img src="./../../assets/images/return.png" width="30%">
      </div>
      <div class="classification_t_r">{{$route.meta.title}}</div>
    </header>
    <div class="personal_information_nickname1" style="margin-top:50px;">
      <div class="p_i_nickname_l1">联系人</div>
      <div class="p_i_nickname_r1">
        <input type="text" placeholder="请填写姓名" v-model="param.linkman">
      </div>
    </div>
    <div class="personal_information_nickname1">
      <div class="p_i_nickname_l1">联系方式</div>
      <div class="p_i_nickname_r1">
        <input type="tel" placeholder="请填写手机号" v-model="param.phone">
      </div>
    </div>
    <div class="personal_information_nickname1" @click="openPositioning">
      <div class="p_i_nickname_l1">所在地区</div>
      <div class="addadres_icon_box">
        <input class="addadres_icon_box_l" type="text" placeholder="省，市，区" v-model="param.address" disabled="disabled" style="font-size: 14px; padding-left: 10px;">
        <div class="addadres_icon_box_r"><img src="@/assets/images/addadres_icon.png"></div>
      </div>
    </div>
    <div class="personal_information_nickname1">
      <div class="p_i_nickname_l1">地址</div>
      <div class="p_i_nickname_r1">
        <input type="text" placeholder="请输入详细地址" v-model="param.address_detail">
      </div>
    </div>
    <div class="index_divide"></div>
    <div class="index_divide"></div>
    <div class="update_btn" @click="doAddadress">
        <input type="submit" value="保存">
    </div>	
  </div>
</template>
<script>
// import TopWithBack from './../common/TopWithBack'
import { addAdress } from '@/api/allapis'
// import { Message, MessageBox, Loading } from 'element-ui'
export default{
  name: 'Addadress',
  data(){
    return{
      param:{
        linkman:'',//联系人
        phone:'',//联系电话
        add_lon:'',//地址lon坐标
        add_lat:'',//地址lat坐标
        address:'',//地址
        adcode:'',//地区adcode
        address_detail:'',//地址具体信息
      },
      item:'',//接收到的地址对象
    }
  },
  // components:{
  //     TopWithBack
  // },
  methods:{
    //打开地图页    
    openPositioning(){
    // console.log(JSON.stringify(this.param))
      this.$router.replace({
        name:'Map',
        params:{
          param:this.param //需要传到地图的数据，避免从地图返回时填写的数据消失
        }
      })
    },
    //添加地址
    doAddadress(){
      if (this.param.linkman == '') {
        this.$vux.toast.show({
          text: '请输入您的姓名',
          type: 'warn',
          time: 800,
        })
        return;
      }
      if (this.param.phone == '') {
        this.$vux.toast.show({
          text: '请输入您的手机号',
          type: 'warn',
          time: 800,
        })
        return;
      }
      if (!(/^1[3|4|5|8]\d{9}$/.test(this.param.phone))) {
        this.$vux.toast.show({
          text: '手机号有误，请重新输入！',
          type: 'warn',
          time: 800,
        })
        return;
      }
      if (this.param.address_detail == '') {
        this.$vux.toast.show({
          text: '请输入详细的地址',
          type: 'warn',
          time: 800,
        })
        return;
      }
      // console.log(JSON.stringify(this.item.location.P))
     
      // console.log(JSON.stringify(this.param))
      const self = this
      addAdress(this.param).then(response=>{
        self.$vux.toast.show({
          text: '添加成功',
          type: 'success',
          time: 800,
          onHide: function () {
            self.$router.go(-1)
          }
        })
      })
    },
    //返回上一页
    goPrev(){
      this.$router.go(-1)
    },
  },
  mounted(){
    //获取从地图页面传过来的数据，responseparam从添加地址页面到地图页返回的数据
    try {
      if(this.$route.params.resonseparam){
        this.item = this.$route.params.item//获取从地图页传过来的地址数据
        // console.log(JSON.stringify(this.item))
        // console.log(JSON.stringify(this.$route.params.item))
        // console.log(JSON.stringify(this.$route.params.adcode))
        // console.log(JSON.stringify(this.param))
        this.param = this.$route.params.resonseparam
        
        // console.log(this.param.linkman)
        this.param.adcode = this.$route.params.adcode//获取从地图传过来的adcode
        this.param.address = this.item.name
        this.param.add_lon = this.item.location.O
        this.param.add_lat = this.item.location.P
        // console.log(JSON.stringify(this.param))
      }
    } catch (error) {
    }
  },
}
</script>
<style>

</style>


